<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js - skinning - simple</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #f0f0f0;
				margin: 0px;
				overflow: hidden;
			}
		</style>
	</head>
	<body>

		<script src="../build/three.js"></script>
		<script src="js/libs/stats.min.js"></script>
		<script src="js/controls/OrbitControls.js"></script>

		<script>

			var container, stats, controls;
			var camera, scene, renderer, loader, clock, light;
			var skinnedMesh, animation, groundMaterial, planeGeometry, mixer;

			init();
			animate();

			function init() {

				container = document.createElement( 'div' );
				document.body.appendChild( container );

				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
				camera.position.set( 10, 0, 10 );

				scene = new THREE.Scene();
				loader = new THREE.JSONLoader();
				clock = new THREE.Clock;

				renderer = new THREE.WebGLRenderer();
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize(window.innerWidth, window.innerHeight);
				container.appendChild( renderer.domElement );

				controls = new THREE.OrbitControls( camera, renderer.domElement );

				stats = new Stats();
				container.appendChild(stats.dom);

				groundMaterial = new THREE.MeshPhongMaterial( { emissive: 0xbbbbbb } );
				planeGeometry = new THREE.PlaneBufferGeometry( 16000, 16000 );
				ground = new THREE.Mesh( planeGeometry, groundMaterial );
				ground.position.set( 0, -5, 0 );
				ground.rotation.x = -Math.PI/2;
				scene.add( ground );

				light = new THREE.HemisphereLight( 0xffffff, 0x003300, 1 );
				light.position.set( - 80, 500, 50 );
				scene.add( light );

				loader.load( './models/skinned/simple/simple.js', function ( geometry, materials ) {

					for ( var k in materials ) {

						materials[k].skinning = true;

					}

					skinnedMesh = new THREE.SkinnedMesh(geometry, new THREE.MultiMaterial(materials));
					skinnedMesh.scale.set( 1, 1, 1 );

					// Note: We test the corresponding code path with this example -
					// you shouldn't include the next line into your own code:
					skinnedMesh.skeleton.useVertexTexture = false;

					scene.add( skinnedMesh );

					mixer = new THREE.AnimationMixer( skinnedMesh );
					mixer.clipAction( skinnedMesh.geometry.animations[ 0 ] ).play();

				});

			}

			function animate() {

				requestAnimationFrame( animate );

				if( mixer ) mixer.update( clock.getDelta() );

				controls.update();

				render();
				stats.update();

			}

			function render() {

				renderer.render( scene, camera );

			}

		</script>
	</body>
</html>
